fix: let browser handle navigation requests to support auth proxies#2069
fix: let browser handle navigation requests to support auth proxies#2069pakerfeldt wants to merge 1 commit intoFlowFuse:mainfrom
Conversation
When the dashboard sits behind an authentication proxy (Cloudflare Access, OAuth2 Proxy, Authelia, etc.), the service worker must not intercept navigation requests. Otherwise it serves a cached index.html, preventing the browser from following HTTP redirects to the login page when the auth session expires. Remove the NavigationRoute + createHandlerBoundToURL registration and disable precacheAndRoute's directoryIndex and cleanURLs options so it cannot implicitly serve index.html for navigation requests. Static assets (JS, CSS, fonts, images) are still served from the precache via exact URL match, so page loads remain fast.
|
With issue #2068 and this PR, I hope we can have a conversation on how to resolve the problem. This PR is a suggested solution that has been proving to work for me, but maybe people with more experience of service workers would come up with a better approach. |
|
As I said in the linked issue I cannot replicate the issue on Android. I can, however, say that I have been running with this PR applied for over a week with a short expiry time on CFZT and have not seen any problems with the PWA install on my Android phone or a PC. |
|
Just a note to say that if anyone is testing anything in this area there can be problems when switching between builds. I have had sometimes to not only uninstall and re-install the app, but also to clear the Chrome cache in order to get it to work reliably. Without clearing the Chrome cache after rebuilding the dashboard source I have sometimes had the PWA hang showing the dashboard icon on startup. |
Description
When the dashboard is deployed behind an authentication proxy (Cloudflare Access, OAuth2 Proxy, Authelia, etc.), the service worker intercepts all navigation requests and serves a cached
index.html. This prevents the browser from following the proxy's HTTP redirect to the login page when the auth session expires, resulting in "There was an error loading the Dashboard."Remove the
NavigationRouteregistration so the service worker never handles navigation requests. The browser performs normal network navigation and can follow auth redirects naturally.To prevent
precacheAndRoutefrom implicitly servingindex.htmlfor navigation requests (via itsdirectoryIndexandcleanURLsdefaults), both options are explicitly disabled.Static asset requests (JS, CSS, fonts, images) are unaffected, they are not navigation requests and continue to be served from the precache via exact URL match.
Testing
Tested behind Cloudflare Access (Zero Trust) with Google IdP:
Related Issue(s)
Fixes #2068
Checklist
Unsure how we would write tests for the service worker.
flowforge.yml?FlowFuse/helmto update ConfigMap TemplateFlowFuse/CloudProjectto update values for Staging/ProductionLabels
area:migrationlabel